#include <iostream>
#include "QuickSort.h"
#include <vector>
#include <ctime>
#include <chrono>
#include <fstream>
void generateRandomNums(string fileName,int n){
    // 打开文件
    ofstream outputFile(fileName);

    // 检查文件是否成功打开
    if (!outputFile.is_open()) {
        std::cerr << "文件打开失败: " << fileName << std::endl;
        return;
    }

    // 生成 n 个随机数并写入文件
    srand(time(0)); // 使用当前时间作为种子
    for (int i = 0; i < n; i++) {
        int randomNumber = std::rand() % (n * 5) + 1;
        outputFile << randomNumber << " ";
    }
    // 关闭文件
    outputFile.close();
}

void shuffle(vector<int>& src , int times){
    for (int i = 0 ; i < times ; i ++){
        int m , n ;
        m = std::rand() % times;
        n = std::rand() % times;
        swap(src[m] , src[n]);
    }
}

void readNums(string fileName,vector<int>& data){

    // 打开文件
    ifstream inputFile(fileName);

    // 检查文件是否成功打开
    if (!inputFile.is_open()) {
        cerr << "文件打开失败: " << fileName << endl;
        return ;
    }

    // 从文件读取随机数到 vector
    int number;
    while (inputFile >> number) {
        data.push_back(number);
    }
    // 关闭文件
    inputFile.close();
}


//#include "Swap.h"
using namespace std;
int main() {
    const auto size = 0b11111111111111 ;
//    generateRandomNums("dat.txt" , size);
//    std::cout << "Hello, World!" << std::endl;

    vector<int> v ;
    for (int i = 0 ; i < size ; i ++){
        v.push_back(i);
    }
//    shuffle(v , 0b1111111111);
//    readNums("dat.txt" , v);

    auto start_time = std::chrono::high_resolution_clock::now();
    quickSort(v , 0 , v.size() - 1);
    auto end_time = std::chrono::high_resolution_clock::now();
//    for (auto it : v){
//        cout << it << endl ;
//    }

    auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end_time - start_time).count();
    std::cout << "Elapsed time: " << duration << " milliseconds" << std::endl;

    return 0;
}
